define(function(require,exports,module){
    var Base={
		mBaserSvrUrl:window.BaseServerUrl,
		localStorage:window.localStorage
	};
	
	function JlnRequest(){
		this.params={}
	}
	module.exports=DataProxy;
function DataProxy(){
	function dataSubmit(request, success, ignoreError) {
	    var url = Base.mBaserSvrUrl+'/data';
        if (request.svr == null) request.svr = undefined;
	    if (request.token == null) request.token = undefined;
	    var content = JSON.stringify(request);
       
	    url = url + '?f=t&data=' + encodeURIComponent(content);
	    url = url + '&CallBack=?';
        $.getJSON(url,success);

	}

	function createDataSetRq(union,name,tag,type,logoUrl,success,ignoreError){
        var request=new JlnRequest();
        request.func='createDataSet';
        request.token = Base.localStorage.getItem('request_token');
		
		request.params['n']=name;
		request.params['t']=tag;
		request.params['t0']=type;
		request.params['lu']=logoUrl;

		if (union == true) {
	        request.svr = 'data';
            request.ignoreError = ignoreError;
	        request.success = success;
        }
	    return request;
    }
	this.createDataSetRequest=function(name,tag,type,logoUrl,success,ignoreError){
       var request= createDataSetRq(true,name,tag,type,logoUrl,success,ignoreError);
       return request;
    }
	this.createDataSet=function(name,tag,type,logoUrl,success,ignoreError){
       var request= createDataSetRq(false,name,tag,type,logoUrl,success,ignoreError);
       dataSubmit(request, success, ignoreError);

    }

	function deleteDataSetRq(union,id,success,ignoreError){
        var request=new JlnRequest();
        request.func='deleteDataSet';
        request.token = Base.localStorage.getItem('request_token');
		
		request.params['id']=id;

		if (union == true) {
	        request.svr = 'data';
            request.ignoreError = ignoreError;
	        request.success = success;
        }
	    return request;
    }
	this.deleteDataSetRequest=function(id,success,ignoreError){
       var request= deleteDataSetRq(true,id,success,ignoreError);
       return request;
    }
	this.deleteDataSet=function(id,success,ignoreError){
       var request= deleteDataSetRq(false,id,success,ignoreError);
       dataSubmit(request, success, ignoreError);

    }

	function getDataSetsRq(union,page,countPerPage,success,ignoreError){
        var request=new JlnRequest();
        request.func='getDataSets';
        request.token = Base.localStorage.getItem('request_token');
		
		request.params['p']=page;
		request.params['cpp']=countPerPage;

		if (union == true) {
	        request.svr = 'data';
            request.ignoreError = ignoreError;
	        request.success = success;
        }
	    return request;
    }
	this.getDataSetsRequest=function(page,countPerPage,success,ignoreError){
       var request= getDataSetsRq(true,page,countPerPage,success,ignoreError);
       return request;
    }
	this.getDataSets=function(page,countPerPage,success,ignoreError){
       var request= getDataSetsRq(false,page,countPerPage,success,ignoreError);
       dataSubmit(request, success, ignoreError);

    }

	function createDataItemRq(union,dataSetId,relationId,relationSid,title,linkUrl,isHot,sortFactor,success,ignoreError){
        var request=new JlnRequest();
        request.func='createDataItem';
        request.token = Base.localStorage.getItem('request_token');
		
		request.params['dsid']=dataSetId;
		request.params['rid']=relationId;
		request.params['rs']=relationSid;
		request.params['t']=title;
		request.params['lu']=linkUrl;
		request.params['ih']=isHot;
		request.params['sf']=sortFactor;

		if (union == true) {
	        request.svr = 'data';
            request.ignoreError = ignoreError;
	        request.success = success;
        }
	    return request;
    }
	this.createDataItemRequest=function(dataSetId,relationId,relationSid,title,linkUrl,isHot,sortFactor,success,ignoreError){
       var request= createDataItemRq(true,dataSetId,relationId,relationSid,title,linkUrl,isHot,sortFactor,success,ignoreError);
       return request;
    }
	this.createDataItem=function(dataSetId,relationId,relationSid,title,linkUrl,isHot,sortFactor,success,ignoreError){
       var request= createDataItemRq(false,dataSetId,relationId,relationSid,title,linkUrl,isHot,sortFactor,success,ignoreError);
       dataSubmit(request, success, ignoreError);

    }

	function createDataItemFromJsonRq(union,dataSetId,jsonData,success,ignoreError){
        var request=new JlnRequest();
        request.func='createDataItemFromJson';
        request.token = Base.localStorage.getItem('request_token');
		
		request.params['dsid']=dataSetId;
		request.params['jd']=jsonData;

		if (union == true) {
	        request.svr = 'data';
            request.ignoreError = ignoreError;
	        request.success = success;
        }
	    return request;
    }
	this.createDataItemFromJsonRequest=function(dataSetId,jsonData,success,ignoreError){
       var request= createDataItemFromJsonRq(true,dataSetId,jsonData,success,ignoreError);
       return request;
    }
	this.createDataItemFromJson=function(dataSetId,jsonData,success,ignoreError){
       var request= createDataItemFromJsonRq(false,dataSetId,jsonData,success,ignoreError);
       dataSubmit(request, success, ignoreError);

    }

	function deleteDataItemRq(union,id,success,ignoreError){
        var request=new JlnRequest();
        request.func='deleteDataItem';
        request.token = Base.localStorage.getItem('request_token');
		
		request.params['id']=id;

		if (union == true) {
	        request.svr = 'data';
            request.ignoreError = ignoreError;
	        request.success = success;
        }
	    return request;
    }
	this.deleteDataItemRequest=function(id,success,ignoreError){
       var request= deleteDataItemRq(true,id,success,ignoreError);
       return request;
    }
	this.deleteDataItem=function(id,success,ignoreError){
       var request= deleteDataItemRq(false,id,success,ignoreError);
       dataSubmit(request, success, ignoreError);

    }

	function getDataItemsByDataSetTagRq(union,dataSetTag,page,countPerPage,success,ignoreError){
        var request=new JlnRequest();
        request.func='getDataItemsByDataSetTag';
        request.token = Base.localStorage.getItem('request_token');
		
		request.params['dst']=dataSetTag;
		request.params['p']=page;
		request.params['cpp']=countPerPage;

		if (union == true) {
	        request.svr = 'data';
            request.ignoreError = ignoreError;
	        request.success = success;
        }
	    return request;
    }
	this.getDataItemsByDataSetTagRequest=function(dataSetTag,page,countPerPage,success,ignoreError){
       var request= getDataItemsByDataSetTagRq(true,dataSetTag,page,countPerPage,success,ignoreError);
       return request;
    }
	this.getDataItemsByDataSetTag=function(dataSetTag,page,countPerPage,success,ignoreError){
       var request= getDataItemsByDataSetTagRq(false,dataSetTag,page,countPerPage,success,ignoreError);
       dataSubmit(request, success, ignoreError);

    }

	function getDataItemsByDataSetIdRq(union,dataSetId,page,countPerPage,success,ignoreError){
        var request=new JlnRequest();
        request.func='getDataItemsByDataSetId';
        request.token = Base.localStorage.getItem('request_token');
		
		request.params['dsi']=dataSetId;
		request.params['p']=page;
		request.params['cpp']=countPerPage;

		if (union == true) {
	        request.svr = 'data';
            request.ignoreError = ignoreError;
	        request.success = success;
        }
	    return request;
    }
	this.getDataItemsByDataSetIdRequest=function(dataSetId,page,countPerPage,success,ignoreError){
       var request= getDataItemsByDataSetIdRq(true,dataSetId,page,countPerPage,success,ignoreError);
       return request;
    }
	this.getDataItemsByDataSetId=function(dataSetId,page,countPerPage,success,ignoreError){
       var request= getDataItemsByDataSetIdRq(false,dataSetId,page,countPerPage,success,ignoreError);
       dataSubmit(request, success, ignoreError);

    }

	function queryProductsByTagRq(union,dataSetTag,page,countPerPage,success,ignoreError){
        var request=new JlnRequest();
        request.func='queryProductsByTag';
        request.token = Base.localStorage.getItem('request_token');
		
		request.params['dst']=dataSetTag;
		request.params['p']=page;
		request.params['cpp']=countPerPage;

		if (union == true) {
	        request.svr = 'data';
            request.ignoreError = ignoreError;
	        request.success = success;
        }
	    return request;
    }
	this.queryProductsByTagRequest=function(dataSetTag,page,countPerPage,success,ignoreError){
       var request= queryProductsByTagRq(true,dataSetTag,page,countPerPage,success,ignoreError);
       return request;
    }
	this.queryProductsByTag=function(dataSetTag,page,countPerPage,success,ignoreError){
       var request= queryProductsByTagRq(false,dataSetTag,page,countPerPage,success,ignoreError);
       dataSubmit(request, success, ignoreError);

    }
}

});
